export const subjectMap = {
  11: '物理',
  12: '历史',
  14: '化学',
  13: '生物',
  15: '政治',
  16: '地理',
  17: '技术',
};

export const subjectShortNameMap = {
  11: '物',
  12: '历',
  13: '生',
  14: '化',
  15: '政',
  16: '地',
  17: '技',
};

const subjectIdMap = {
  物理: 11,
  历史: 12,
  化学: 14,
  生物: 13,
  政治: 15,
  地理: 16,
  技术: 17,
};

const subjectTypeMap = {
  不限: 10, // 文理不限
  物理: 11, // 理科
  历史: 12, // 文科
};

export const mainSubjectList = [
  {
    name: '物理',
    shortName: '物',
    checked: false,
    id: '11',
  },
  {
    name: '历史',
    shortName: '历',
    checked: false,
    id: '12',
  },
];

export const minorSubjectList = [
  {
    name: '化学',
    shortName: '化',
    checked: false,
    id: '14',
  },
  {
    name: '生物',
    shortName: '生',
    checked: false,
    id: '13',
  },
  {
    name: '政治',
    shortName: '政',
    checked: false,
    id: '15',
  },
  {
    name: '地理',
    shortName: '地',
    checked: false,
    id: '16',
  },
];

export const sixSubjectList = [
  {
    name: '物理',
    shortName: '物',
    checked: false,
    id: '11',
  },
  {
    name: '化学',
    shortName: '化',
    checked: false,
    id: '14',
  },
  {
    name: '生物',
    shortName: '生',
    checked: false,
    id: '13',
  },
  {
    name: '历史',
    shortName: '历',
    checked: false,
    id: '12',
  },
  {
    name: '政治',
    shortName: '政',
    checked: false,
    id: '15',
  },
  {
    name: '地理',
    shortName: '地',
    checked: false,
    id: '16',
  },
];

export const getSubjectName = (code) => {
  if (!code) return '';
  return code
    .split(',')
    .map((item) => subjectMap[item])
    .join('+');
};

export const getSubjectShortName = (code) => {
  if (!code) return '';
  return code
    .split(',')
    .map((item) => subjectShortNameMap[item])
    .join('+');
};

export const getSubjectCode = (name) => {
  if (!name) return '';
  return Object.keys(subjectMap).find((key) => subjectMap[key] === name);
};

export const getSubjectIdByName = (name) => {
  if (!name) return '';
  return subjectIdMap[name];
};

export const getSubjectTypeByName = (name) => {
  if (!name) return '';
  return subjectTypeMap[name];
};

export const formatData = (str, key) => {
  const temp = JSON.parse(str);
  if (Array.isArray(temp)) {
    return temp.map((item) => {
      return {
        name: item.showName,
        value: item[key],
      };
    });
  } else {
    return [];
  }
};
